import type { Login } from "@/interface/Login";
import request from "@/common/Ask";
import type { User } from "@/interface/User";
import type { Query } from "@/interface/Query";
import type { Page } from "@/interface/Page"
import type { UserTenement } from "@/interface/UserTenement";
import type { UserRole } from "@/interface/UserRole";
import type {LoginRes} from "@/interface/LoginRes";

export async function loginApi( data : Login) {
    return request<LoginRes>({
        url: 'user/login',
        method: 'put',
        data: data
    });
}

export async function listApi( data : Query ) {
    return request<Page<User>>({
        url: 'user/list',
        method: 'post',
        data: data
    });
}

export async function workerApi( data : Query ) {
    return request<Page<User>>({
        url: 'user/worker',
        method: 'post',
        data: data
    });
}

export async function workerOperateApi( data : User ) {
    return request<number>({
        url: 'user/workerOperate',
        method: 'put',
        data: data
    });
}

export async function operatorApi( data : User ) {
    return request<string>({
        url: 'user/add',
        method: 'put',
        data: data
    });
}


export async function adminBindSelectApi(data ? : string) {
    return request<any>({
        url: data ? `user/adminBindSelect/${data}` : 'user/adminBindSelect',
        method: 'get',
    });
}


export async function bindPropertyApi(data : UserTenement) {
    return request<boolean>({
        url: 'user/bindProperty',
        method: 'put',
        data: data
    });
}

export async function userRoleOperatorApi(data : UserRole) {
    return request<boolean>({
        url: 'userRole/operator',
        method: 'put',
        data: data
    });
}

export async function getUserRolesApi( data : string ) {
    return request<string[]>({
        url: 'userRole/roleIds/' + data,
        method: 'get',
    });
}


export async function loginOutApi() {
    return request<boolean>({
        url: 'user/loginOut',
        method: 'get',
    });
}

export async function removeWorkerApi(ids : string[]) {
    return request<boolean>({
        url: 'user/removeWorker',
        method: 'delete',
        data: ids
    });
}


export async function residentOperateApi(user : User,houseId ? : string ) {
    return request<string>({
        url: houseId ? `user/residentOperate/${houseId}` : 'user/residentOperate',
        method: 'put',
        data: user
    });
}

export async function repairWorkerApi(word ?: string){
    return request<User[]>({
        url: word ? `user/repairWorker/${word}` : 'user/repairWorker',
        method: 'get',
    });
}


export async function twinsApi() {
    return request<string>({
        url: 'user/twins',
        method: 'get',
    });
}

export async function statisticsApi( userId : string ) {
    return request<any>({
        url: 'user/statistics/' + userId,
        method: 'get',
    });
}

export async function oneIdApi( id : string ) {
    return request<User>({
        url: 'user/oneId/' + id,
        method: 'get',
    })
}

export async function updatePersonalInfoApi( user : User ) {
    return request<boolean>({
        url: 'user/updatePersonalInfo',
        method: 'put',
        data: user
    });
}


export async function changePwdApi( data : { userId : string , oldPwd : string, newPwd : string } ) {
    return request<boolean>({
        url: 'user/changePwd',
        method: 'put',
        data: data
    });
}
